package cn.iocoder.yudao.module.bpm.message.kafka.custom.processTask;


import cn.iocoder.yudao.module.bpm.message.consts.ProcessTaskStreamKey;
import cn.iocoder.yudao.module.bpm.message.handle.ProcessTaskMessageHandle;
import cn.iocoder.yudao.module.bpm.message.rocketmq.dto.RocketMqBpmProcessTaskAssignedMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;

@Slf4j
@RequiredArgsConstructor
public class KafkaProcessTaskAssignedCustom {

    private final ProcessTaskMessageHandle processTaskMessageHandle;

    @KafkaListener(
            topics = ProcessTaskStreamKey.PROCESS_INSTANCE_TASK_ASSIGNED_MSG_STREAM,
            groupId = ProcessTaskStreamKey.PROCESS_INSTANCE_TASK_ASSIGNED_MSG_GROUP +"_" + "${spring.application.name}"
    )
    public void onMessage(RocketMqBpmProcessTaskAssignedMessage message) {
        try {
            log.info("消费消息：{}", message);
            processTaskMessageHandle.onProcessInstanceTaskAssignedMsg(message.getBpmProcessMessage());
        } catch (Exception e) {
            log.error("MQ消费失败", e);
            throw new RuntimeException(e.getMessage());
        }
    }

}
